using System;
using System.Collections.Generic;
using System.Linq;
namespace TemplateWeb.Models.BUS
{
	#region using
	using TemplateWeb.Helpers;
	using TemplateWeb.Models.ViewModels;
	using TemplateWeb.Models;
    using TemplateWeb.DTO;
    using TemplateWeb.DAO;
    using System.Data;
	#endregion
	public class ToChucCaNhanBUS
	{
		public List<ToChucCaNhanDTO> SelectAll()
		{
			try
			{
                var lstDto = new List<ToChucCaNhanDTO>();
                var rpt = new ToChucCaNhanDAO(WebConfiguration.DbConnectionString);
                var objDS = rpt.SelectAll();
                if (objDS != null && objDS.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow row in objDS.Tables[0].Rows)
                    {
                        lstDto.Add(ToChucCaNhanDTO.Translate(row));
                    }
                }
                return lstDto;
			}
			catch(Exception ex)
			{
				if(ex.InnerException != null)
					CommonLogging.Logger.Error("ToChucCaNhan - SelectAll: " + ex.InnerException.Message.Replace("\t", string.Empty).Replace("\r", string.Empty).Replace("\n", string.Empty));
				else
					CommonLogging.Logger.Error("ToChucCaNhan - SelectAll: " + ex.Message.Replace("\t", string.Empty).Replace("\r", string.Empty).Replace("\n", string.Empty));
				return new List<ToChucCaNhanDTO>();
			}
		}

		public ToChucCaNhanDTO SelectByID(int id)
		{
			try
			{
                var rpt = new ToChucCaNhanDAO(WebConfiguration.DbConnectionString);
                var objDS = rpt.SelectByID(id);
                if (objDS != null && objDS.Tables[0].Rows.Count > 0)
                {
                    return ToChucCaNhanDTO.Translate(objDS.Tables[0].Rows[0]);
                }
			}
			catch(Exception ex)
			{
				if(ex.InnerException != null)
					CommonLogging.Logger.Error("ToChucCaNhan - SelectByID: " + ex.InnerException.Message.Replace("\t", string.Empty).Replace("\r", string.Empty).Replace("\n", string.Empty));
				else
					CommonLogging.Logger.Error("ToChucCaNhan - SelectByID: " + ex.Message.Replace("\t", string.Empty).Replace("\r", string.Empty).Replace("\n", string.Empty));
			}
            return null;
		}

		public bool Insert(ToChucCaNhanDTO obj)
		{
			try
			{
                var rpt = new ToChucCaNhanDAO(WebConfiguration.DbConnectionString);
                return rpt.Insert(obj);
			}
			catch(Exception ex)
			{
				if(ex.InnerException != null)
					CommonLogging.Logger.Error("ToChucCaNhan - Insert: " + ex.InnerException.Message.Replace("\t", string.Empty).Replace("\r", string.Empty).Replace("\n", string.Empty));
				else
					CommonLogging.Logger.Error("ToChucCaNhan - Insert: " + ex.Message.Replace("\t", string.Empty).Replace("\r", string.Empty).Replace("\n", string.Empty));
				return false;
			}
		}

		public bool Delete(int id)
		{
			try
			{
                var rpt = new ToChucCaNhanDAO(WebConfiguration.DbConnectionString);
                return rpt.Delete(id);
			}
			catch(Exception ex)
			{
				if(ex.InnerException != null)
					CommonLogging.Logger.Error("ToChucCaNhan - Delete: " + ex.InnerException.Message.Replace("\t", string.Empty).Replace("\r", string.Empty).Replace("\n", string.Empty));
				else
					CommonLogging.Logger.Error("ToChucCaNhan - Delete: " + ex.Message.Replace("\t", string.Empty).Replace("\r", string.Empty).Replace("\n", string.Empty));
				return false;
			}
		}

		public bool Update(ToChucCaNhanDTO obj)
		{
			try
			{
                var rpt = new ToChucCaNhanDAO(WebConfiguration.DbConnectionString);
                return rpt.Update(obj);
			}
			catch
			{
				return false;
			}
		}

	}
}